<?
	include("../header.php");
?>
<link rel="stylesheet" type="text/css" href="../style/style.css" />
<?
include("config.php");
include("function.php");
// get kategori form
$show	= $HTTP_GET_VARS['cat'];
// get data form employee
$nik	= $HTTP_GET_VARS['nik'];
// get data from pendidikan formal
$no		= $HTTP_GET_VARS['no'];
// tahun
$tahun	= $HTTP_GET_VARS['tahun'];
// username
$username 	= $HTTP_GET_VARS['usr'];
// jenis cuti
$jenis_cuti = $HTTP_GET_VARS['jenis_cuti'];

if($show == "employee"){
	///////////////////
	
}
elseif($show == "pendidikan"){
	///////////////////
	$sql = "WITH limit AS (SELECT ROW_NUMBER() OVER (ORDER BY Dari) AS no, * FROM Pendidikan WHERE NIK='$nik' ) DELETE FROM limit WHERE no='$no'  ";
	//	echo"$nik, $show, $no";		
	$cat = "delete"; // category query
	InsertData($conn,$sql,$cat);
}
// approval keluarga
elseif($show == "appr_keluarga"){
	///////////////////
	//WITH limit AS (SELECT ROW_NUMBER() OVER (ORDER BY NIK) AS no, * FROM Keluarga WHERE NIK='$nik' ) DELETE FROM limit WHERE no='$no'  

	$sql = mssql_query("WITH limit AS (SELECT ROW_NUMBER() OVER (ORDER BY Nm_Keluarga) AS no, * FROM Keluarga WHERE NIK='".$nik."' ) UPDATE limit SET aktif='A' WHERE no='".$no."'",$conn);
	//	echo"$nik, $show, $no";		
	//$cat = "delete"; // category query
	//InsertData($conn,$sql,$cat);
	if($sql){
		echo"
		<script language='Javascript'>
			history.back();
		</script>
		";
	}
	else{
		echo"
		<div align=center>
		<br><br><br>
		Maaf, proses pertujuan tidak bisa dilakukan ... <br><br>
		<a href='Javascript:hostory.back()'>Silahkan Kembali</a>
		</div>
		";
	}
}
elseif($show == "kursus"){
	///////////////////
	$sql = "WITH limit AS (SELECT ROW_NUMBER() OVER (ORDER BY NIK) AS no, * FROM Kursus WHERE NIK='$nik' ) DELETE FROM limit WHERE no='$no'  ";
	$cat = "delete"; // category query
	InsertData($conn,$sql,$cat);
}
elseif($show == "par_cat_lp2"){
	///////////////////
	$sql = "DELETE FROM S_LP_Cat_Nilai WHERE category='$nik' ";
	$cat = "delete"; // category query
	InsertData($conn,$sql,$cat);
}
// delete dokumen pegawai
elseif($show == "dokumen"){
	// cek file
	$sql = mssql_query("WITH limit AS (SELECT ROW_NUMBER() OVER (ORDER BY NIK) AS No,* FROM S_File_Emp WHERE NIK='$nik') SELECT * FROM limit WHERE No='$no'",$conn);
	$row = mssql_fetch_array($sql);
	if(file_exists("../dokumen/$row[filenya]")){
		// hapus file
		if(unlink("../dokumen/$row[filenya]")){
			$sdel = mssql_query("WITH limit AS (SELECT ROW_NUMBER() OVER (ORDER BY NIK) AS No,* FROM S_File_Emp WHERE NIK='$nik') DELETE FROM limit WHERE No='$no'");
			if($sdel){
				echo"
				<br><br><br><br>
				<center>
				 File sudah dihapus ...<br>
				 <a href='Javascript:history.back();'>Silahkan Kembali</a>
				</center>
				";
			}
			else{
				echo"
				<br><br><br><br>
				<center>
				 File sudah tidak bisa dihapus ...<br>
				 <a href='Javascript:history.back();'>Silahkan Kembali</a>
				</center>
				";
			}
		}
		else{
				echo"
				<br><br><br><br>
				<center>
				 File sudah tidak bisa dihapus ...<br>
				 <a href='Javascript:history.back();'>Silahkan Kembali</a>
				</center>
				";
		}
	}
	else{
		echo"
		<br><br><br><br>
		<center>
		 File sudah tidak bisa dihapus ...<br>
		 File tersebut tidak ada<br>
		 <a href='Javascript:history.back();'>Silahkan Kembali</a>
		</center>
		";
	}
}
elseif($show == "keluarga"){
	///////////////////
	$sql = "WITH limit AS (SELECT ROW_NUMBER() OVER (ORDER BY Nm_Keluarga) AS no, * FROM Keluarga WHERE NIK='$nik' ) DELETE FROM limit WHERE no='$no'  ";
	$cat = "delete"; // category query
	InsertData($conn,$sql,$cat);
}
elseif($show == "karir"){
	///////////////////
	$sql = "WITH limit AS (SELECT ROW_NUMBER() OVER (ORDER BY NIK) AS no, * FROM Karir WHERE NIK='$nik' ) DELETE FROM limit WHERE no='$no'  ";
	$cat = "delete"; // category query
	InsertData($conn,$sql,$cat);
}
elseif($show == "organisasi"){
	///////////////////
	$sql = "WITH limit AS (SELECT ROW_NUMBER() OVER (ORDER BY NIK) AS no, * FROM Organisasi WHERE NIK='$nik' ) DELETE FROM limit WHERE no='$no'  ";
	$cat = "delete"; // category query
	InsertData($conn,$sql,$cat);
}
elseif($show == "kecakapan"){
	///////////////////
	$sql = "WITH limit AS (SELECT ROW_NUMBER() OVER (ORDER BY NIK) AS no, * FROM Bahasa WHERE NIK='$nik' ) DELETE FROM limit WHERE no='$no'  ";
	$cat = "delete"; // category query
	InsertData($conn,$sql,$cat);
}
elseif($show == "pengalamanLN"){
	///////////////////
	$sql = "WITH limit AS (SELECT ROW_NUMBER() OVER (ORDER BY NIK) AS No, * FROM PengalamanLN WHERE NIK='$nik' ) DELETE FROM limit WHERE No='$no'  ";
	$cat = "delete"; // category query
	InsertData($conn,$sql,$cat);
}
elseif($show == "pengalamanRef"){
	///////////////////
	$sql = "WITH limit AS (SELECT ROW_NUMBER() OVER (ORDER BY NIK) AS No, * FROM PengalamanRef WHERE NIK='$nik' ) DELETE FROM limit WHERE No='$no'  ";
	$cat = "delete"; // category query
	InsertData($conn,$sql,$cat);
}
elseif($show == "karir_ptsi"){
	///////////////////
	$sql = "WITH limit AS (SELECT ROW_NUMBER() OVER (ORDER BY NIK) AS No, * FROM KarirPTSI WHERE NIK='$nik') DELETE FROM limit WHERE No='$no'  ";
	$cat = "delete"; // category query
	InsertData($conn,$sql,$cat);
}
elseif($show == "track_record"){
	///////////////////
	$sql = "WITH limit AS (SELECT ROW_NUMBER() OVER (ORDER BY NIK) AS No, * FROM MK_TrackRecords WHERE NIK='$nik') DELETE FROM limit WHERE No='$no'  ";
	$cat = "delete"; 
	InsertData($conn,$sql,$cat);
}
elseif($show == "sanksi"){
	///////////////////
	$sql = "WITH limit AS (SELECT ROW_NUMBER() OVER (ORDER BY NIK) AS No, * FROM Sanksi WHERE NIK='$nik') DELETE FROM limit WHERE No='$no'  ";
	$cat = "delete"; 
	InsertData($conn,$sql,$cat);
}
elseif($show == "penilaian"){
	$sql = "WITH limit AS (SELECT ROW_NUMBER() OVER (ORDER BY NIK) AS No, * FROM LP2Detail WHERE NIK='$nik') DELETE FROM limit WHERE No='$no'  ";
	$cat = "delete"; 
	InsertData($conn,$sql,$cat);
	//*/
}
elseif($show == "Fpenilaian"){	

	$sql = "DELETE FROM LP2 WHERE NIK='$nik' AND Tahun='$no' ";
	$cat = "delete"; 
	InsertData($conn,$sql,$cat);
	//*/
}
elseif($show == "LP"){	

	$sql = "DELETE FROM S_LP WHERE id='$no' ";
	$cat = "delete"; 
	InsertData($conn,$sql,$cat);
	//*/
}
// cuti khusus
elseif($show == "cuti_khusus"){
	$sql = "DELETE FROM Cuti WHERE id='$no' AND NIK='$nik' ";
	$cat = "delete"; 
	InsertData($conn,$sql,$cat);
}
// cuti tahunan
elseif($show == "cuti_tahunan"){
	$sql = "WITH limit AS (SELECT * FROM CutiTahunan WHERE NIK='$nik') DELETE FROM limit WHERE id='$no'  ";
	$cat = "delete"; 
	InsertData($conn,$sql,$cat);
}
// cuti besar
elseif($show == "cuti_besar"){
	//echo"$nik,".$HTTP_GET_VARS['periode'];
	//exit;
	//$sql = "WITH limit AS (SELECT ROW_NUMBER() OVER (ORDER BY periode) AS No, * FROM Cuti WHERE NIK='$nik' AND periode='".$HTTP_GET_VARS['periode']."' AND id_JenisCuti='2') DELETE FROM limit WHERE No='$no'  ";
	$sql = "DELETE FROM Cuti WHERE id='$no' AND NIK='$nik' ";
	$cat = "delete"; 
	InsertData($conn,$sql,$cat);
}
// delete plafon awal
elseif($show == "plafon_awal"){
	$sql = "WITH limit AS (SELECT ROW_NUMBER() OVER (ORDER BY NIK) AS No, * FROM MedicalSetupAwal WHERE NIK='$nik') DELETE FROM limit WHERE No='$no'  ";
	$cat = "delete"; 
	InsertData($conn,$sql,$cat);
}
// delete penugasan
elseif($show == "penugasan"){
	$sql = "WITH limit AS (SELECT ROW_NUMBER() OVER (ORDER BY NIK) AS No, * FROM Penugasan WHERE NIK='$nik') DELETE FROM limit WHERE No='$no'  ";
	$cat = "delete"; 
	InsertData($conn,$sql,$cat);
}
// delete data medical
elseif($show == "medical"){
	$sqla = mssql_query("DELETE FROM MedicalRestitusi WHERE NIK='$nik' AND nomor='$no' ",$conn);
	if($sqla){
		$sql = "DELETE FROM MedicalRestitusiDetail WHERE NIK='$nik' AND nomor='$no' ";
		$cat = "delete"; 
		InsertData($conn,$sql,$cat);
	}
	else{
		echo"
		<div align=center style='color: red;'>
		Penghapusan data tidak dapat dilakukan, ... <br><br>
		[ <a href='Javascript:history.back();'>kembali</a> ]		
		";
	}
}
// delete parameter lokasi
elseif($show == "par_lokasi"){
		$sql = "DELETE FROM MstLokasi WHERE kode_lokasi='$nik' ";
		$cat = "delete"; 
		InsertData($conn,$sql,$cat);
}
// delete parameter lp2
elseif($show == "par_lp2"){
		$sql = "DELETE FROM MstUnsurLP2 WHERE UnsurID='$nik' ";
		$cat = "delete"; 
		InsertData($conn,$sql,$cat);
}
// delete parameter fungsional
elseif($show == "par_fungsional"){
		$sql = "DELETE FROM MstFungsional WHERE kode='$nik' ";
		$cat = "delete"; 
		InsertData($conn,$sql,$cat);
}
// delete parameter jenis cuti
elseif($show == "par_jns_cuti"){
		$sql = "DELETE FROM MstJenisCuti WHERE id_jcuti='$nik' ";
		$cat = "delete"; 
		InsertData($conn,$sql,$cat);
}
// delete parameter pendidikan
elseif($show == "par_pendidikan"){
		$sql = "DELETE FROM MstPendidikan WHERE Pend_ID='$nik' ";
		$cat = "delete"; 
		InsertData($conn,$sql,$cat);
}
// delete parameter bank
elseif($show == "par_bank"){
		$sql = "DELETE FROM MstBank WHERE IdBank='$nik' ";
		$cat = "delete"; 
		InsertData($conn,$sql,$cat);
}
// delete parameter jabatan
elseif($show == "par_jabatan"){
		$sql = "DELETE FROM MstJabatan WHERE kode='$nik' ";
		$cat = "delete"; 
		InsertData($conn,$sql,$cat);
}
// delete parameter PARAMETER SETUP (ALL)
elseif($show == "par_setup"){
		$sql = "DELETE FROM MstData WHERE GroupCode='$nik' AND Code='$no' ";
		$cat = "delete"; 
		InsertData($conn,$sql,$cat);
}
// delete user 
elseif($show == "add_user"){
		$sql = "DELETE FROM S_User WHERE username='$username'";
		$cat = "delete";
		InsertData($conn,$sql,$cat);
}
// delete group user
elseif($show == "add_group"){
		//echo $_GET['usr'];
		//exit();
		mssql_query("DELETE FROM S_Priv_User WHERE group_id='".$_GET['usr']."'",$conn);
		
		$sql = "DELETE FROM S_User_Group WHERE group_id='".$_GET['usr']."'";
		$cat = "delete";
		InsertData($conn,$sql,$cat);
}
// delete unit kerja/mst so
elseif($show == "tbl_unit_kerja"){
		$sql = "DELETE FROM MstSO WHERE kode_so='$nik'";
		$cat = "delete";
		InsertData($conn,$sql,$cat);
}
// delete mk certified
elseif($show == "certified"){
//WITH limit AS (SELECT ROW_NUMBER() OVER (ORDER BY Cert_Date) as No, *, year(Cert_Date) tahun_sertifikat, CONVERT(CHAR(12), Cert_Date, 103) tgl_sertifikat, CONVERT(CHAR(12), Cert_Date_Exp, 103) tgl_expire FROM MK_Certification WHERE NIK='$nik') SELECT * FROM limit 

	$sql = "WITH limit AS (SELECT ROW_NUMBER() OVER (ORDER BY Cert_Date) AS No, * FROM MK_Certification WHERE NIK='$nik') DELETE FROM limit WHERE No='$no'  ";
	$cat = "delete"; 
	InsertData($conn,$sql,$cat);
}

echo"</div>
	  </td>
	   </tr>
	    </table>
";
include("../menu.php");
?>
